import React from 'react'
import PureRenderMixin from 'react-addons-pure-render-mixin'

import { getInfoData } from '../../../fetch/detail/detai';
import DetailInfo from '../../../components/DetailInfo';

import { infoMock } from '../../../fetch/staticMock/detail';//静态假数据

class Info extends React.Component {
    constructor(props, context) {
        super(props, context);
        this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
        this.state={
            info:false
        }
    }
    render() {
        return (
            <div>
                {
                    this.state.info
                    ? <DetailInfo data={this.state.info}/>
                    : <div>loading...</div>
                }
            </div>
        )
    }
    componentDidMount(){
        var id=this.props.id;
        // var result=getInfoData(id);
        // result.then(res => {
        //     return res.json()
        // }).then(json=>{
        //    this.setState({
        //        info:json
        //    })
        // }).catch(ex => {
        //     if (__DEV__) {
        //         console.error('获取info数据出错, ', ex.message)
        //     }
        // });

        //模拟静态假数据
        
        function timerHandle(infoMock){
            this.setState({
                info:infoMock
            })
        }
        setTimeout(timerHandle.bind(this,infoMock),100);

    }
}

// 使用 require.ensure 异步加载，还不支持 ES6 的 export
export default Info